package com.demo.day0308;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
部门1
 */
@WebServlet(name = "Demo01Servlet", urlPatterns = "/demo01.do")
public class Demo01Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Post");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Get");
        //获取前端传过来的参数
        String username = request.getParameter("username");
        System.out.println(username);
        System.out.println("在Servlet1(柜台1)中查看参数");
        //在request对象作用域中存放一个值 key:value形式
        request.setAttribute("key1", "柜台1的公章");
        //转发到/demo02.do路径，可以将request作用域中的值带过去
        //   /由后端进行解析
        request.getRequestDispatcher("/demo02.do").forward(request, response);

    }
}
